package com.gitee.liuzhi.demo.juc.threadpoolexecutor.threadpool;

import com.gitee.liuzhi.demo.juc.threadpoolexecutor.conf.ThreadPoolConfiguration;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程池
 *
 * @Author liuzhi
 * @Date 2023/9/6 20:39
 * @Version 1.0
 * @Description
 */
public class MyThreadPoolExecutor {

    private static ThreadPoolExecutor myThreadPoolExecutor;

    private MyThreadPoolExecutor() {

    }

    public static ThreadPoolExecutor getInstance() {
        if (null == myThreadPoolExecutor) {
            myThreadPoolExecutor = new ThreadPoolExecutor(
                    ThreadPoolConfiguration.corePoolSize,
                    ThreadPoolConfiguration.maximumPoolSize,
                    ThreadPoolConfiguration.keepAliveTime,
                    ThreadPoolConfiguration.timeUnit,
                    ThreadPoolConfiguration.workQueue,
                    ThreadPoolConfiguration.threadFactory,
                    ThreadPoolConfiguration.rejectedExecutionHandler);
        }
        return myThreadPoolExecutor;
    }

}
